package calss_1_21exception;

import java.util.Scanner;

public class Login {
    public static final String USER="小明";
    public static final String PASSWORD="123456";
    public static void main(String[] args) {
        try {
            login();
            System.out.println("登录成功！");
        } catch (UserNameException e) {
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }
    public static void login(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name=scanner.next();
        System.out.println("请输入密码：");
        String password= scanner.next();
        if(!USER.equals(name)){
            //抛出用户名异常
            throw new UserNameException("用户名输出错误~~");
        }
        if(!PASSWORD.equals(password)){
            //抛出密码异常
            throw new PasswordException("密码输入错误");
        }
    }
}
//用户名异常
class UserNameException extends RuntimeException{
    public UserNameException(String msg){
        super(msg);
    }
}
//密码异常
class PasswordException extends RuntimeException{
    public PasswordException(String msg){
        super(msg);
    }
}